package com.xy.biz.ts.domain.bo;

import com.xy.tool.context.UserContextHolder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 *
 *
 * @author zgy
 * @date 2021-6-28
 */
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Data
public class TrainFlowHandleBO {

    /**
     * 培训流程节点Id
     */
    private Long trainFlowHandleId;
    /**
     * 培训Id
     */
    private Long trainId;
    /**
     * 阶段：0-未定义
     */
    private String phase;
    /**
     * 结果：0未定义，1-通过，2-驳回，3-终止流程，4-取消流程
     */
    private Integer result;
    /**
     * 处理意见
     */
    private String opinion;
    /**
     * 处理人用户Id
     */
    private Long handleUserId;
    /**
     * 处理人用户名
     */
    private String handleUserName;
    /**
     * 处理人部门Id
     */
    private Long handleUserGroupId;
    /**
     * 处理人部门名
     */
    private String handleUserGroupName;
    /**
     * 培训流程类型：
     train_type_common_train-普通培训，
     train_type_document_train-文档培训
     */
    private String flowType;
    /**
     * 培训分类
     train_year-年度培训
     train_common-普通培训
     */
    private String trainClassify;
    /**
     * 租户Id，0表示不指定
     */
    private Long tenantId;
    /**
     * 创建人用户Id
     */
    private Long createUserId;
    /**
     * 创建时间
     */
    private LocalDateTime createTime;
    /**
     * 更新时间
     */
    private LocalDateTime updateTime;
    /**
     * 是否是培训总结流程标识：0-否，1-是
     */
    private Boolean trainSumFlag;
    /**
     * 删除标识：0-正常，1-删除
     */
    private Boolean deleteFlag;

    public static TrainFlowHandleBO build(TrainBO trainBO,
                                          Long handleUserId,
                                          Long handleUserGroupId,
                                          String phase,
                                          int result,
                                          Boolean isTrainSumFlag,
                                          String opinion) {
        TrainFlowHandleBO trainFlowHandleBO = new TrainFlowHandleBO();
        LocalDateTime now = LocalDateTime.now();
        trainFlowHandleBO.setTrainId(trainBO.getTrainId());
        trainFlowHandleBO.setPhase(phase);
        trainFlowHandleBO.setResult(result);
        trainFlowHandleBO.setOpinion(opinion);
        trainFlowHandleBO.setHandleUserId(handleUserId);
        trainFlowHandleBO.setHandleUserGroupId(handleUserGroupId);
        trainFlowHandleBO.setFlowType(trainBO.getTrainClassify());
        trainFlowHandleBO.setTrainClassify(trainBO.getTrainClassify());
        trainFlowHandleBO.setTenantId(UserContextHolder.getTenantId());
        trainFlowHandleBO.setCreateUserId(UserContextHolder.getUserId());
        trainFlowHandleBO.setCreateTime(now);
        trainFlowHandleBO.setUpdateTime(now);
        trainFlowHandleBO.setTrainSumFlag(isTrainSumFlag);
        trainFlowHandleBO.setDeleteFlag(false);
        trainBO.addHandle(trainFlowHandleBO);
        return trainFlowHandleBO;
    }

    public static TrainFlowHandleBO build(TrainSumBO trainSumBO,
                                          Long handleUserId,
                                          Long handleUserGroupId,
                                          String phase,
                                          int result,
                                          Boolean isTrainSumFlag,
                                          String opinion) {
        TrainFlowHandleBO trainFlowHandleBO = new TrainFlowHandleBO();
        LocalDateTime now = LocalDateTime.now();
        trainFlowHandleBO.setTrainId(trainSumBO.getTrainSumId());
        trainFlowHandleBO.setPhase(phase);
        trainFlowHandleBO.setResult(result);
        trainFlowHandleBO.setOpinion(opinion);
        trainFlowHandleBO.setHandleUserId(handleUserId);
        trainFlowHandleBO.setHandleUserGroupId(handleUserGroupId);
        trainFlowHandleBO.setFlowType(null);
        trainFlowHandleBO.setTrainClassify(null);
        trainFlowHandleBO.setTenantId(UserContextHolder.getTenantId());
        trainFlowHandleBO.setCreateUserId(UserContextHolder.getUserId());
        trainFlowHandleBO.setCreateTime(now);
        trainFlowHandleBO.setUpdateTime(now);
        trainFlowHandleBO.setTrainSumFlag(isTrainSumFlag);
        trainFlowHandleBO.setDeleteFlag(false);
        trainSumBO.addHandle(trainFlowHandleBO);
        return trainFlowHandleBO;
    }

}
